<html>
<head><meta charset="utf-8"><title>Doubts regarding adding a new module assist · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Doubts.20regarding.20adding.20a.20new.20module.20assist.html">Doubts regarding adding a new module assist</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="245946848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Doubts%20regarding%20adding%20a%20new%20module%20assist/near/245946848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Fenil Jain <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Doubts.20regarding.20adding.20a.20new.20module.20assist.html#245946848">(Jul 14 2021 at 11:24)</a>:</h4>
<p>Hey everyone, I had a look at <a href="https://github.com/rust-analyzer/rust-analyzer/issues/9591">https://github.com/rust-analyzer/rust-analyzer/issues/9591</a> and would like to work on it. While thinking about the process I have a couple of doubts I want to get clarified:</p>
<ul>
<li>How will the assist get invoked? Issue mentions selection, but I have no idea if its possible, most other assists seem to use cursor position as the reference. If it possible, is there some guide? If not, where do we invoke it from(maybe from the struct/func def)?</li>
<li>On what node types can we invoke it? struct and function?</li>
<li>Lets say we are doing it for a struct, as mentioned in issue, will it mean taking all impl blocks of that struct(even from different files)?</li>
</ul>



<a name="245946994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Doubts%20regarding%20adding%20a%20new%20module%20assist/near/245946994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Doubts.20regarding.20adding.20a.20new.20module.20assist.html#245946994">(Jul 14 2021 at 11:26)</a>:</h4>
<p>"Extract type alias" uses the current selection</p>



<a name="245947044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Doubts%20regarding%20adding%20a%20new%20module%20assist/near/245947044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Doubts.20regarding.20adding.20a.20new.20module.20assist.html#245947044">(Jul 14 2021 at 11:27)</a>:</h4>
<p>the new assist should work on any collection of items, I think</p>



<a name="247849291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Doubts%20regarding%20adding%20a%20new%20module%20assist/near/247849291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Fenil Jain <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Doubts.20regarding.20adding.20a.20new.20module.20assist.html#247849291">(Aug 01 2021 at 09:12)</a>:</h4>
<p>Hey, what could be the best way to rename a given struct/function/enum, etc. over all instances, I was trying to do it with to_def finding refs, and then trying to replace, but it seems to be a lot of work, I guessed I will confirm once.</p>



<a name="247851234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Doubts%20regarding%20adding%20a%20new%20module%20assist/near/247851234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Doubts.20regarding.20adding.20a.20new.20module.20assist.html#247851234">(Aug 01 2021 at 10:03)</a>:</h4>
<p>Yes, going with <code>to_def</code> and then finding references seems like the correct approach for this</p>



<a name="248592159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Doubts%20regarding%20adding%20a%20new%20module%20assist/near/248592159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Fenil Jain <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Doubts.20regarding.20adding.20a.20new.20module.20assist.html#248592159">(Aug 06 2021 at 10:10)</a>:</h4>
<p>Hey, what could be the best way to resolving imports in this case. I would have to move/retain/duplicate imports according to the content selected for extraction in new module, so there could be references I would have to shift to new module, or keep in both, new module and container module. Any reference I could be guided to?</p>



<a name="248594993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Doubts%20regarding%20adding%20a%20new%20module%20assist/near/248594993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Doubts.20regarding.20adding.20a.20new.20module.20assist.html#248594993">(Aug 06 2021 at 10:34)</a>:</h4>
<p>Hmm, you probably want to do usage searches of all the items in your selection</p>



<a name="248595147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Doubts%20regarding%20adding%20a%20new%20module%20assist/near/248595147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Doubts.20regarding.20adding.20a.20new.20module.20assist.html#248595147">(Aug 06 2021 at 10:36)</a>:</h4>
<p>So basically you want to go through all NameRefs in your selection, turn them to hir nodes via <code>NameRefClass::classify</code>, then do <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_db/src/search.rs#L307">usage searches</a> on them with the file as a scope, that way you can check if you find imports in the current file, as well as whether this name ref is used outside of your selection</p>



<a name="248595167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Doubts%20regarding%20adding%20a%20new%20module%20assist/near/248595167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Doubts.20regarding.20adding.20a.20new.20module.20assist.html#248595167">(Aug 06 2021 at 10:36)</a>:</h4>
<p>Limiting the search to your file cna be done with <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_db/src/search.rs#L334-L336">https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_db/src/search.rs#L334-L336</a></p>



<a name="248595189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Doubts%20regarding%20adding%20a%20new%20module%20assist/near/248595189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Doubts.20regarding.20adding.20a.20new.20module.20assist.html#248595189">(Aug 06 2021 at 10:36)</a>:</h4>
<p>Similar thing can be applied to <code>Name</code>s since you would move those definitions you want to know what paths to fix up</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>